package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.DictionaryDAO;
import com.pojo.Dictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("dictionaryService")
public class DictionaryService extends ServiceImpl<DictionaryDAO, Dictionary> {

    @Autowired
    private DictionaryDAO dictionaryDAO;

    public List<Dictionary> getDicByType (String type){
        return dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("type",type));
    }

    public List<Dictionary> getDicByZyGs (){
        return dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("type","Zy").eq("value","gs"));
    }

    public List<Dictionary> getDicByZyJt (){
        return dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("type","Zy").eq("value","jt"));
    }

    public Dictionary getDicByName (String type, String name){
        List<Dictionary> dicList = dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("name",name).eq("type",type));
        if (dicList.size() >0) {
            return dicList.get(0);
        }
        return null;
    }

    public Dictionary getDicByCode (String type, String code){
        List<Dictionary> dicList = dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("code",code).eq("type",type));
        if (dicList.size() >0) {
            return dicList.get(0);
        }
        return null;
    }

    public List<Dictionary> getDicByParams (String type, String extParams){
        List<Dictionary> dicList = dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("type",type).eq("ext_params",extParams));
        if (dicList.size() >0) {
            return dicList;
        }
        return new ArrayList<Dictionary>();
    }

    public List<Dictionary> getDicByParams2 (String type, String extParams){
        List<Dictionary> dicList = dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("type",type).eq("ext_params2",extParams));
        if (dicList.size() >0) {
            return dicList;
        }
        return new ArrayList<Dictionary>();
    }

}
